<script type="text/javascript">
    var searchProperty = "<?php echo $searchProperty;?>";
    var searchField = "<?php echo $searchField;?>";
    var searchText = "<?php echo $searchText;?>";
    var catalogId = "<?php echo $catalogId;?>";
    var subCatalogId = "<?php echo $subCatalogId;?>";
    var contentTypeId = "<?php echo $contentTypeId;?>";
    
    function checkAll(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
          checkall[i].checked=true;
       }
    }
    function checkInvert(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
           if(checkall[i].checked)
                checkall[i].checked=false;
           else
                checkall[i].checked=true;     
       }
    }

    function actionFun(content,actionType){
        var confirmResult = false;
        //if(content == null && actionType)
        switch(actionType)
        {
            case "delete":
                confirmResult = confirm('确定要删除？');
                break;
            case "publish":
                confirmResult = confirm('确定要发布？');
                break;
            case "cancelPublish":
                confirmResult = confirm('确定要取消发布？');
                break;
            case "cancelTop":
                confirmResult = confirm('确认要取消置顶？');
                break;
            case "top":
                confirmResult = confirm('确认要置顶？');
                break;
            case "recommend":
                confirmResult = confirm('确认要推荐？');
                break;
            case "cancelRecommend":
                confirmResult = confirm('确认要取消推荐？');
                break;
            case "focus":
                confirmResult = confirm('确认要焦点？');
                break;
            case "cancelFocus":
                confirmResult = confirm('确认要取消焦点？');
                break;
        }
        if(actionType == "search")
            confirmResult = true;
        if(confirmResult)
        {
            if(1==content && actionType != "search"){
                var checkall=document.getElementsByName('check_all');
                content="";
                for(var i=0;i<checkall.length;i++)
                {
                    if(checkall[i].checked)
                        content+=checkall[i].value+" ";
                }
            }
            if(catalogId != "")
                content += "&catalogId=" + catalogId;
            if (subCatalogId != "")
                content += "&subCatalogId=" + subCatalogId;
            if(contentTypeId != "")
                content += "&contentTypeId=" + contentTypeId;
            if(actionType == "search")
            {
                if($("#sSearchProperty").val() != "none")
                    content += "&searchProperty=" + $("#sSearchProperty").val();
                if($("#sSearchField").val() != "none")
                    content += "&searchField=" + $("#sSearchField").val();
                var searchCondition = $.trim($("#txtSearch").val());
                if (searchCondition != "") {
                    content += "&searchText=" + searchCondition;
                }
            }
            window.location="<?php echo url_for("video/index?submitType=");?>" + actionType + "&content="+content;
        }
    }

    function editInfo(content){
        if(contentTypeId != "")
           content += "/contentTypeId/" + contentTypeId;
        window.location="<?php echo url_for("video/edit?videoEdit=1&content=");?>"+content;;
    }

    function onAdd()
    {
         var url = "<?php echo url_for("video/add");?>";
         if(contentTypeId != "")
             url +="?contentTypeId=" + contentTypeId;
         if(catalogId != "")
         {
             if(url == "<?php echo url_for("news/add");?>")
                 url +="?catalogId=" + catalogId;
             else
                 url +="&catalogId=" + catalogId;
         }
         if(subCatalogId != "")
         {
             if(url == "<?php echo url_for("news/add");?>")
                 url += "?subCatalogId=" + subCatalogId;
             else
                 url += "&subCatalogId=" + subCatalogId;
         }
         window.location = url;
    }
    $(document).ready(function()
    {
        if(searchProperty != "")
           $("#sSearchProperty").val(searchProperty);
        if(searchField != "")
           $("#sSearchField").val(searchField);
        $("#txtSearch").val(searchText);
    });

</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-right:10px;">
  <tr>
    <td style="height:30px;">
	 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>位置：<?php echo $navigator;?></td>
    <td></td>
  </tr>
</table>
	</td>
  </tr>
  <tr>
    <td style="height:30px;">
	     <table width="100%" border="0" cellspacing="0" cellpadding="0">
             <tr>
                 <td>
                     <input id="add" type="button" onclick="onAdd()" value="添加视频" />
<input id="del" type="button" onclick="actionFun(1,'delete');" value="删除视频" /></td>
                 <td align="right">搜索：
                   <select name="sSearchProperty" id="sSearchProperty" onchange="actionFun(null,'search')">
                     <option value="none">不限属性</option>
                     <option value="top">置顶</option>
                     <option value="recommend">推荐</option>
                     <option value="focus">焦点</option>
                     <option value="publish">发布</option>
                     <option value="delete">删除</option>
                   </select>
				   <input name="txtSearch" type="text" id="txtSearch" />
				     <select name="sSearchField" id="sSearchField" onchange="actionFun(null,'search')">
				       <option value="none">不限字段</option>
				       <option value="title">标题</option>
				       <option value="keyword">关键字</option>
				       <option value="tag">Tag 值</option>
			         </select>
			         <input name="btnSearch" type="button" id="btnSearch" value="搜索" onclick="actionFun(null,'search')" />				                 </td>
             </tr>
           </table>

	</td>
  </tr>
  <tr>
    <td>
<?php
        //echo $aaa;
           echo "<table cellspacing=0' cellpadding='4' border='1' style=\"width:100%;color:#333333;border-collapse:collapse;\"><tr style=\"color:White;background-color:#5D7B9D;font-weight:bold;height:25px;\"><td style=\"width:50px;\" align=\"center\">ID</td><td style=\"width:30px;\" align=\"center\">选择</td><td align=\"center\">标题</td><td style=\"width:100px;\" align=\"center\">发布者</td><td style=\"width:70px;\" align=\"center\">点击率</td><td style=\"width:80px;\" align=\"center\">状态</td><td style=\"width:80px;\" align=\"center\">发布时间</td><td style=\"width:70px;\" align=\"center\">操作</td><td align='center' style=\"width:40px;\">预览</td></tr>";
           $videos = @$pages->getResults();
           $i = 0;
           foreach($videos as $row=>$video)
           {
               $videoTypeStr = "";
               if($video->getIsOnTopB())
                   $videoTypeStr = $videoTypeStr." [置顶]";
               if($video->getIsRecommendB())
                   $videoTypeStr = $videoTypeStr." [荐]";
               if($video->getIsFocusB())
                   $videoTypeStr = $videoTypeStr." [焦]";
               //id,title,发布者，发布时间，（编辑，删除）image_tag('edit.png')
               if($i%2 == 0)
                   $trStyle = "style=\"color:#333333;background-color:#F7F6F3;height:30px;\"";
               else
                   $trStyle = "style=\"color:#284775;background-color:White;height:30px;\"";
               echo "<tr ".$trStyle."><td>".$video->getVideo_id()."</td><td align=\"center\"><input type='checkbox' name='check_all' value='".$video->getVideo_id()."' /></td><td>".link_to($video->getTitle().$videoTypeStr,"video/edit?videoEdit=1&content=".$video->getVideoId()."&contentTypeId=".$sf_request->getParameter("contentTypeId"))
                       ."</td><td>admin</td><td>".$video->getHit_i()."</td><td>".$video->getStatus()->getName()."</td><td align=\"center\">".date('Y/m/d',strtotime($video->getPublish_time()))
                       ."</td><td align=\"center\"><img border='0' title='编辑' src='/sfDoctrinePlugin/images/edit.png'onclick='editInfo(".$video->getVideo_id().");' style='cursor:pointer;' />"
                       ."&nbsp;&nbsp;"
                       ."<img border='0' title='删除' src='/sfDoctrinePlugin/images/delete.png'onclick='actionFun(".$video->getVideo_id().",\"delete\");' style='cursor:pointer;' /></td><td align='center'><a href='/index.php/video/detail?videoId=".$video->getVideoId()."' target='_blank'>预览</a></td></tr>";
               $i++;
           }
           echo "</table>";
           $numPages= $pages->getLastPage();
           $CurrentPageID=$pages->getPage();
             if(@$pages->haveToPaginate())
			{
				$str=$CurrentPageID-6;
				$end=$CurrentPageID+5;
				if($str<0)
					$str=0;
				if($end>$numPages)
					$end=$numPages;
				echo "<div class='page_list'>";
                $catalogStr = "";
                if($contentTypeId != null)
                    $catalogStr="&contentTypeId=".$contentTypeId;
                if($catalogId != null)
                    $catalogStr=$catalogStr."&catalogId=".$catalogId;
                if($subCatalogId != null)
                    $catalogStr = $catalogStr."&subCatalogId=".$subCatalogId;
				if($CurrentPageID>1)
					echo link_to("首页","video/index?currentPage=1".$catalogStr).link_to("上一页","video/index?currentPage=".($CurrentPageID-1).$catalogStr);
				 for($i=$str;$i<$end;$i++)
				 {
					if($i==($CurrentPageID-1)){
					echo "<a class='now02' href='#'>".($i+1)."</a>";}
					else{
					    echo link_to(($i+1),"video/index?currentPage=".($i+1).$catalogStr);
                    }
				 }
				 if($CurrentPageID<$numPages)
				    echo link_to("下一页","video/index?currentPage=".($CurrentPageID+1).$catalogStr).link_to("末页","video/index?currentPage=".$numPages.$catalogStr);
				 echo "</div>";
			}
?>
	</td>
  </tr>
  <tr>
    <td valign="middle" style="height:30px;">
	<input type='button' onclick='checkAll();' value='全选' /> <input type='button' onclick='checkInvert();' value='反选' /> <input type='button' onclick='actionFun(1,"publish");' value='发布' /> <input type='button' onclick='actionFun(1,"cancelPublish");' value='取消发布' /> <input type='button' onclick='actionFun(1,"recommend");' value='推荐' /> <input type='button' onclick='actionFun(1,"cancelRecommend");' value='取消推荐' /> <input type='button' onclick='actionFun(1,"top");' value='置顶' /> <input type='button' onclick='actionFun(1,"cancelTop");' value='取消置顶' /> <input type='button' onclick='actionFun(1,"cancelFocus");' value='取消焦点' /></td>
  </tr>
  <tr>
      <td>

	  </td>
  </tr>
</table>
